package Presentation;

import java.awt.Color;
import java.awt.Component;
import javax.swing.AbstractCellEditor;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;

public class LabelColumn extends AbstractCellEditor implements TableCellRenderer {

    private final JLabel[] jl;
    
    public LabelColumn(JTable table, int column){
        jl = new JLabel[table.getRowCount()];
        for(int i = 0 ; i < table.getRowCount() ; i++){
            jl[i] = new JLabel((String)table.getValueAt(i, 0));
            jl[i].setBorder(new LineBorder(Color.BLACK));
            jl[i].setHorizontalAlignment(SwingConstants.CENTER);
        }
        
        TableColumnModel columnModel = table.getColumnModel();
        columnModel.getColumn(column).setCellRenderer(this);
    }
    

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        return jl[row];
    }

    public Object getValue(int row){
        return jl[row];
    }

    @Override
    public Object getCellEditorValue() {
        return jl;
    }
    
}
